<!--
 * @Author: suo.tianbao suo.tianbao@vpclub.cn
 * @Date: 2023-07-24
 * @LastEditors: suo.tianbao suo.tianbao@vpclub.cn
 * @LastEditTime: 2023-07-24
 * @FilePath: /element-admin/src/views/MemberInfo.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div id="MemberWeightCal-page">
    <!-- bodyer -->
    <div class="drawer-bodyer">
      <el-row class="row fstRow clearfix">
        <el-button @click="childMethod()" size="small">关闭</el-button>
      </el-row>
    </div>
    <!--顶部搜索栏-->
    <div class="col-md-12">
      <el-row :gutter="20">
        <el-col :span="22" :offset="1" class="clearfix">
          <el-form :model="HealthCM" label-width="100px" v-loading="calDataLoad">
            <el-card class="box-card">
              <template #header>
                <div class="card-header">
                  <span style="font-size: 22px;">A.会员基础参数</span>
                  <el-button type="primary" class="register_btn" size="small"
                             @click.native="handle_calories_food_catalog_fetch">确认指标
                  </el-button>
                </div>
              </template>
              <el-row :gutter="10">
                <el-col :sm="6" :xs="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="姓名">
                    <span style="font-size: 22px;">{{ HealthCM.name }}</span>
                  </el-form-item>
                </el-col>
                <el-col :sm="6" :xs="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="性别">
                    <el-select v-model="HealthCM.sex" placeholder="性别" size="small" @change="cal_sex_cofficient()">
                      <el-option label="请选择性别" value=-1></el-option>
                      <el-option :label="item.label" :value=item.value :data="item" v-for="item in sex_options"
                                 v-bind:key="item.value"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :sm="6" :xs="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="年龄">
                    <el-input v-model="HealthCM.age" placeholder="年龄" size="small" :clearable="true"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="10">
                <el-col :sm="6" :xs="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="身高(m)">
                    <el-input v-model="HealthCM.height" placeholder="身高" size="small"
                              :clearable="true" @change="cal_calories_fat()"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :sm="6" :xs="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="体重(kg)">
                    <el-input v-model="HealthCM.weight" placeholder="体重" size="small"
                              :clearable="true" @change="cal_calories_fat()"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :sm="6" :xs="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="运动系数">
                    <el-tooltip effect="dark" content="计算体质热量数值"
                                placement="right">
                      <el-select v-model="HealthCM.motionFrequency" placeholder="运动系数" size="small"
                                 @change="cal_sex_cofficient()">
                        <el-option label="请选择运动频率" value=-1></el-option>
                        <el-option :label="item.label" :value=item.value :data="item"
                                   v-for="item in motionFrequency_options"
                                   v-bind:key="item.value"></el-option>
                      </el-select>
                    </el-tooltip>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="10">
                <el-col :span="22" :offset="1" class="clearfix">
                  <el-descriptions title="热量计算基数" :column="5" size="small" border direction="vertical">
<!--                    <el-descriptions-item label="BMI系数">-->
<!--                      <el-tooltip effect="dark" content="(体重 / (身高 * 身高))" placement="right">-->
<!--                        <span>{{ HealthCM.BMI }}</span>-->
<!--                      </el-tooltip>-->
<!--                    </el-descriptions-item>-->
<!--                    <el-descriptions-item label="体脂率(m)">-->
<!--                      <el-tooltip effect="dark" content="(固定系数 * BMI) + (体重系数 * 体重) - 计算基数"-->
<!--                                  placement="right">-->
<!--                        <span>{{ HealthCM.bodyFatRat }}</span>-->
<!--                      </el-tooltip>-->
<!--                    </el-descriptions-item>-->
                    <!-- <el-descriptions-item label="计算基数">{{ stat_cal_std }}</el-descriptions-item>-->
                    <el-descriptions-item label="生物静态指标">{{ HealthCM.loss_A }}</el-descriptions-item>
                    <el-descriptions-item label="生物动态指标">{{ HealthCM.loss_B }}</el-descriptions-item>
                    <el-descriptions-item label="体质热量">{{ HealthCM.calories }}</el-descriptions-item>
                  </el-descriptions>
                </el-col>
              </el-row>
              <el-divider/>
              <el-row :gutter="10">
                <!--                <el-col :sm="6" :xs="6" :md="6" :lg="6" :xl="6">-->
                <!--                  <el-form-item label="生物静态系数">-->
                <!--                    <el-tooltip effect="dark" content="依据性别改变基础数值" placement="right">-->
                <!--                      <el-input v-model="HealthCM.staticCoefficient " placeholder="生物静态系数" size="small"-->
                <!--                                :clearable="true" @change="cal_calories_fat()"></el-input>-->
                <!--                    </el-tooltip>-->
                <!--                  </el-form-item>-->
                <!--                </el-col>-->
                <!--                <el-col :sm="6" :xs="6" :md="6" :lg="6" :xl="6">-->
                <!--                  <el-form-item label="生物动态系数">-->
                <!--                    <el-tooltip effect="dark" content="依据性别改变基础数值" placement="right">-->
                <!--                      <el-input v-model="HealthCM.dynamicCoefficient" placeholder="生物动态系数" size="small"-->
                <!--                                :clearable="true" @change="cal_calories_fat()"></el-input>-->
                <!--                    </el-tooltip>-->
                <!--                  </el-form-item>-->
                <!--                </el-col>-->
                <el-col :sm="6" :xs="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="体质热量">
                    <el-tooltip effect="dark" content="总消耗（打卡 / 焦） = 生物动态指标 + 生物静态指标"
                                placement="right">
                      <el-input v-model="HealthCM.calories" placeholder="卡路里" size="small" disabled></el-input>
                    </el-tooltip>
                  </el-form-item>
                </el-col>
                <el-col :sm="6" :xs="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="热量缺口">
                    <el-tooltip effect="dark" content="热量缺口值"
                                placement="right">
                      <el-input v-model="HealthCM.calorGap" placeholder="卡路里" size="small"
                                :clearable="true" @change="cal_calories_std"></el-input>
                    </el-tooltip>
                  </el-form-item>
                </el-col>
                <el-col :sm="6" :xs="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="热量期望值">
                    <el-tooltip effect="dark" content="热量期望值"
                                placement="right">
                      <el-input v-model="HealthCM.calCalorGap" placeholder="卡路里" size="small"></el-input>
                    </el-tooltip>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="10">
                <el-col :sm="6" :xs="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="蛋白质">
                    <el-tooltip effect="dark" content="体重（斤）* 蛋白质系数" placement="right">
                      <el-input v-model="HealthCM.proteinFactor" placeholder="蛋白质系数" size="small"
                                :clearable="true" @change="cal_calories_std()"></el-input>
                    </el-tooltip>
                  </el-form-item>
                </el-col>
                <el-col :sm="6" :xs="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="脂肪">
                    <el-tooltip effect="dark" content="体重（斤）* 脂肪系数" placement="right">
                      <el-input v-model="HealthCM.fatCoefficient" placeholder="脂肪系数" size="small"
                                :clearable="true" @change="cal_calories_std()"></el-input>
                    </el-tooltip>
                  </el-form-item>
                </el-col>
                <el-col :sm="6" :xs="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="碳水">
                    <el-tooltip effect="dark" content="（（摄入总热量）-（脂肪大卡）-（蛋白质大卡））/ 碳水化合物系数"
                                placement="right">
                      <el-input v-model="HealthCM.carbonWaterCoefficient" placeholder="碳水系数" size="small"
                                :clearable="true" @change="cal_calories_std()"></el-input>
                    </el-tooltip>
                  </el-form-item>
                </el-col>
                <el-col :sm="6" :xs="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="维生素占热量比重(%)">
                    <el-input v-model="HealthCM.vitaminCoefficient" placeholder="维生素占热量比重" size="small"
                              :clearable="true" @change.native="cal_calories_std()" disabled></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="10">
                <el-col :span="22" :offset="1" class="clearfix">
                  <el-descriptions title="热量指标（单位：大卡）" :column="4" size="small" border direction="vertical">
                    <el-descriptions-item label="蛋白质热量(大卡 / 克重)">{{ HealthCM.proteinStd }} /
                      {{ HealthCM.proteinWeight }}
                    </el-descriptions-item>
                    <el-descriptions-item label="脂肪热量(大卡 / 克重)">{{ HealthCM.fatStd }} / {{
                        HealthCM.fatWeight
                      }}
                    </el-descriptions-item>
                    <el-descriptions-item label="碳水热量(大卡 / 克重)">{{ HealthCM.carbonWaterStd }} /
                      {{ HealthCM.carbonWaterWeight }}
                    </el-descriptions-item>
                    <el-descriptions-item label="维他命热量(大卡 / 克重)">{{ HealthCM.vitaminStd }} /
                      {{ HealthCM.vitaminWeight }}
                    </el-descriptions-item>
                  </el-descriptions>
                </el-col>
              </el-row>
            </el-card>
          </el-form>
        </el-col>
      </el-row>
    </div>
    <!--中部数据表格栏-->
    <div class="col-md-12" style="margin-top: 15px">
      <el-row :gutter="20">
        <el-col :span="22" :offset="1" class="clearfix">
          <el-card class="box-card" style="margin-bottom: 15px">
            <template #header>
              <div class="card-header">
                <span style="font-size: 22px;">B.食材配比计算 </span>
                <el-button type="warning" class="register_btn" size="small" @click.native="handle_calories_food_fetch">
                  食材配量计算
                </el-button>
              </div>
            </template>
            <el-row :gutter="10">
              <el-col :span="22" :offset="1" class="clearfix">
                <el-descriptions title="每日品类摄入克重（单位：克）" :column="4" size="small" border direction="vertical">
                  <el-descriptions-item label="蛋白质克重">{{ HealthCM.proteinWeight }}</el-descriptions-item>
                  <el-descriptions-item label="脂肪克重">{{ HealthCM.fatWeight }}</el-descriptions-item>
                  <el-descriptions-item label="碳水克重">{{ HealthCM.carbonWaterWeight }}</el-descriptions-item>
                  <el-descriptions-item label="维他命克重">{{ HealthCM.vitaminWeight }}</el-descriptions-item>
                </el-descriptions>
              </el-col>
              <el-col :span="22" :offset="1" class="clearfix">
                <el-table :data="tableData" v-loading="isLoading" border stripe
                          :cell-style="{padding:'3px'}" :key="isIndex" style="margin-top:15px;width: 100%"
                          row-key="id">
                  <el-table-column v-if="isIndex == 1" type="index" label="序号" width="75" fixed></el-table-column>
                  <el-table-column fixed prop="labelRecognition" label="食材标签" width="120px"/>
                  <el-table-column fixed prop="classification" label="食材类别" width="120px"/>
                  <el-table-column fixed prop="count" label="选择食材数量">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.count" placeholder="选择食材数量" size="small" :clearable="true"
                                @change.native="(val) => cal_DailyTake(val,'count',scope.row)"/>
                    </template>
                  </el-table-column>
                  <!--                <el-table-column fixed prop="combinationRatio" label="组合配比(%)">-->
                  <!--                  <template slot-scope="scope">-->
                  <!--                    <el-input v-model="scope.row.combinationRatio" placeholder="配比" size="small" :clearable="true"-->
                  <!--                              @change.native="(val) => cal_DailyTake(val,'combinationRatio',scope.row)"/>-->
                  <!--                  </template>-->
                  <!--                </el-table-column>-->
                  <!--                <el-table-column fixed prop="standardUnit" label="标准单位(份)">-->
                  <!--                  <template slot-scope="scope">-->
                  <!--                    <el-input v-model="scope.row.standardUnit" placeholder="标准单位" size="small" :clearable="true"-->
                  <!--                              @change.native="(val) => cal_DailyTake(val,'standardUnit',scope.row)"/>-->
                  <!--                  </template>-->
                  <!--                </el-table-column>-->
                  <el-table-column fixed prop="oneCatalogsIntake" label="平均单类食材(克)">
                    <template slot-scope="scope">
                      {{ scope.row.oneCatalogsIntake }}
                    </template>
                  </el-table-column>
                  <el-table-column fixed prop="oneDinnerIntake" label="单餐摄入量(克)">
                    <template slot-scope="scope">
                      {{ scope.row.oneDinnerIntake }}
                    </template>
                  </el-table-column>
                  <el-table-column fixed prop="calories" label="卡路里(J)" v-if="false"/>
                </el-table>
              </el-col>
            </el-row>
          </el-card>
        </el-col>
      </el-row>
    </div>
    <div class="col-md-12" style="margin-top: 15px;margin-bottom: 40px" v-loading.fullscreen.lock="fullscreenLoading">
      <el-row :gutter="20">
        <el-col :span="22" :offset="1" class="clearfix">
          <el-card class="box-card" style="margin-bottom: 15px">
            <template #header>
              <div class="card-header">
                <span style="font-size: 22px;">C.食材搭配方案</span>
              </div>
            </template>
            <el-col :span="22" :offset="1" class="clearfix">
              <div v-for="(item, idx1) in tableData2" v-bind:key="idx1" style="margin-bottom: 15px">
                <span>Day: {{ idx1 + 1 }}</span>
                <el-card v-for="(cans, idx2) in item" v-bind:key="idx2" class="dinnerCard">
              <span>
                <el-tag size="small"><span style="font-weight: bold">{{ "[" + cans.name + "]" }}</span></el-tag>
                <el-table :data="cans.foods" v-loading="isLoading" border stripe
                          :cell-style="{padding:'3px'}" :key="isFoodIndex" style="margin-top:5px;width: 100%"
                          row-key="index">
                  <el-table-column v-if="isFoodIndex == 1" type="index" label="序号" width="75" fixed></el-table-column>
                  <el-table-column prop="name" label="配餐"/>
                  <el-table-column prop="classification" label="食材分类"/>
                  <el-table-column prop="key" label="食材"/>
                  <el-table-column prop="intake" label="配餐量(克)"/>
                  <el-table-column prop="unit_content_index" label="百单位含量(克)"/>
                </el-table>
              </span>
                </el-card>
              </div>
              <div style="padding: 14px;">
                <div class="bottom clearfix">
                  <span>{{ desp }}</span>
                  <time class="time" style="margin-left: 15px">{{ currentDate }}</time>
                </div>
              </div>
            </el-col>
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>

</template>

<script>
import {calFoodCatalogs, calPairings} from "@/api/hcmvApi";
import {fetchOne,} from "@/api/MemberWeight";
import {Loading, Message} from 'element-ui';

export default {
  name: "MemberWeightCal",
  components: {},
  data() {
    return {
      loadingInstance: null,
      labelWidth: "140px",
      member_id: '',
      isIndex: 1,
      isFoodIndex: 1,
      isLoading: false,
      calDataLoad: false,
      fullscreenLoading: false,
      tableHeight: 650,
      stat_bmi_std: 1.2,// 固定系数
      stat_weight_std: 0.23,// 体重系数
      stat_cal_std: 16.2,// 计算基数
      HealthCM: {},
      sex_options: [
        {label: "男", value: 0, key: 0},
        {label: "女", value: 1, key: 1},
      ],
      motionFrequency_options: [
        {label: "无训练痕迹", value: 2, key: 0},
        {label: "周训练3-4次", value: 3, key: 1},
        {label: "专业运动员", value: 4, key: 2},
      ],
      claflg: false,
      calParam: [],
      calParamIdx: [],
      tableData: [],
      tableData2: [],
      currentDate: new Date(),
      desp: "",
    }
  },
  props: {
    drawId: {type: String, default: ''}
  },
  computed: {},
  methods: {
    init_obj() {
      return {
        age: 0,
        sex: 0,
        weight: 0,
        height: 0,
        BMI: 0,
        bodyFatRat: 0,
        motionFrequency: 0,
        calories: 0,
        calorGap: 0,
        calCalorGap: 0,
        loss_A: 0,
        loss_B: 0,
        staticCoefficient: 0,
        dynamicCoefficient: 0,
        proteinFactor: 0,
        proteinStd: 0,
        proteinWeight: 0,
        fatCoefficient: 0,
        fatStd: 0,
        fatWeight: 0,
        carbonWaterCoefficient: 0,
        carbonWaterStd: 0,
        carbonWaterWeight: 0,
        vitaminCoefficient: 0,
        vitaminStd: 0,
        vitaminWeight: 0,
      }
    },
    handle_init() {
      this.HealthCM = this.init_obj();
      this.tableData = [];
      this.tableData2 = [];
      // 读取会员数据
      this.handle_mem_fetch(this.member_id);
    },
    async handle_mem_fetch(drawId) {
      fetchOne({"memberId": drawId}).then(res => {
        if (res.code == 200) {
          this.HealthCM = res.data;
        }
      }).catch(err => {
        // Message.error('错了哦，STEP 1 参数异常' + err);
        this.$notify({title: '执行失败', message: '计算参数异常' + err, type: 'error', offset: 100});
      })
    },
    handle_std_confirm() {
      this.calParam = [];
      let load_rows = this.tableData;
      if (load_rows.length == 0) {
        this.$notify({title: '计算失败', message: '请先计算基础数据', type: 'warning', offset: 100});
        return
      }
      load_rows.forEach((element) => {
        this.calParamIdx.push(element.id);
        this.calParam.push({
          "id": element.id,
          "labelRecognition": element.labelRecognition,
          "classification": element.classification,
          "count": element.count,
          "intake": element.oneCatalogsIntake,
        });
      })
      this.claflg = true;
    },
    handle_calories_food_catalog_fetch() {
      this.tableData = [];
      let param = {
        "calories": this.HealthCM.calCalorGap,
        "proteinStd": this.HealthCM.proteinStd,
        "proteinWeight": this.HealthCM.proteinWeight,
        "fatStd": this.HealthCM.fatStd,
        "fatWeight": this.HealthCM.fatWeight,
        "carbonWaterStd": this.HealthCM.carbonWaterStd,
        "carbonWaterWeight": this.HealthCM.carbonWaterWeight,
        "vitaminStd": this.HealthCM.vitaminStd,
        "vitaminWeight": this.HealthCM.vitaminWeight,
      }
      calFoodCatalogs(param).then(res => {
        if (res.code == 200) {
          this.isLoading = false;
          this.tableData = res.data;
          // Message.success("参数核算完成")
          this.$notify({title: '通知', message: '食材配比数据读取完成', type: 'success', offset: 100});
        }
      }).catch(err => {
        // Message.error('错了哦，STEP 1 参数异常' + err);
        this.$notify({title: '执行失败', message: '计算参数异常' + err, type: 'error', offset: 100});
      })
    },
    handle_calories_food_fetch() {
      this.handle_std_confirm();
      if (!this.claflg) {
        this.$notify({title: '计算失败', message: '确认食材配比方案', type: 'warning', offset: 100});
        return
      }
      this.tableData2 = [];
      this.fullscreenLoading = true;
      calPairings({"memberId": this.member_id, "params": this.calParam}).then(res => {
        if (res.code == 200) {
          this.tableData2 = res.data.list;
          this.currentDate = res.data.currentDate;
          this.desp = res.data.desp;
          this.fullscreenLoading = false;
          this.$notify({
            title: '通知',
            message: '配餐参数核算完成',
            offset: 100
          });
        }
      }).catch(err => {
        Message.error('错了哦，STEP 1 参数异常' + err);
        this.fullscreenLoading = false;
      })
    },
    cal_sex_cofficient() {
      // 这里交由后台读取用户数据时候进行计算
      if (this.HealthCM.sex == "0") {
        //   男性系数
        this.HealthCM.staticCoefficient = 20;
        // this.HealthCM.dynamicCoefficient = 30 / 100;
      } else {
        //   女性系数
        this.HealthCM.staticCoefficient = 18;
        // this.HealthCM.dynamicCoefficient = 20 / 100;
      }
      if (this.HealthCM.motionFrequency == 2) {
        this.HealthCM.dynamicCoefficient = 20 / 100;
      } else if (this.HealthCM.motionFrequency == 3) {
        this.HealthCM.dynamicCoefficient = 30 / 100;
      } else if (this.HealthCM.motionFrequency == 4) {
        this.HealthCM.dynamicCoefficient = 40 / 100;
      }
      this.cal_calories_fat(); // 加入卡路里计算
    },
    cal_calories_fat() {
      // IF(P2=0,0,O2/(POWER(P2,2)))
      let cal_h = this.HealthCM.height / 100;
      let cal_w = this.HealthCM.weight;
      let BMI = (cal_w / (cal_h * cal_h));
      this.HealthCM.BMI = this.formattedNumber(BMI); //计算BMI基础值
      // =(1.2*N2)+(0.23*$D$2)-16.2
      let FAT = (this.stat_bmi_std * this.HealthCM.BMI) + (this.stat_weight_std * cal_w) - this.stat_cal_std;
      this.HealthCM.bodyFatRat = this.formattedNumber(FAT);
      // 调整计算公式 总消耗（打卡/焦）动态消耗值+静态消耗值
      // 动态消耗值=静态消耗值*动态系数
      // 静态消耗值=静态系数*体重
      this.HealthCM.loss_A = this.HealthCM.weight * this.HealthCM.staticCoefficient;
      this.HealthCM.loss_B = this.HealthCM.loss_A * this.HealthCM.dynamicCoefficient;
      this.HealthCM.calories = this.HealthCM.loss_A + this.HealthCM.loss_B;
      if (this.HealthCM.calories == 0) {
        this.$notify({
          title: '参数异常',
          message: '输入参数核验失败，请选择性别确认热量计算系数，生物静态系数，生物动态系数',
          type: 'warning',
          offset: 100
        });
        return;
      }
      this.HealthCM.loss_A = this.formattedNumber(this.HealthCM.loss_A);
      this.HealthCM.loss_B = this.formattedNumber(this.HealthCM.loss_B);
      this.HealthCM.calories = this.formattedNumber(this.HealthCM.calories);
      // this.handle_calories_food_catalog_fetch(); 取消上述数值改变后，调用后台计算功能。交由前端计算。
    },
    cal_calories_gap() {
      this.HealthCM.calCalorGap = this.HealthCM.calories - this.HealthCM.calorGap;
    },
    clear_cal_calories_std() {
      this.HealthCM.proteinStd = 0;
      this.HealthCM.fatStd = 0;
      this.HealthCM.carbonWaterStd = 0;
      this.HealthCM.vitaminStd = 0;
      this.HealthCM.proteinWeight = 0;
      this.HealthCM.fatWeight = 0;
      this.HealthCM.carbonWaterWeight = 0;
      this.HealthCM.vitaminWeight = 0;
    },
    format_cal_calories_weight() {
      this.HealthCM.proteinStd = this.formattedNumber(this.HealthCM.proteinStd);
      this.HealthCM.fatStd = this.formattedNumber(this.HealthCM.fatStd);
      this.HealthCM.carbonWaterStd = this.formattedNumber(this.HealthCM.carbonWaterStd);
      this.HealthCM.vitaminStd = this.formattedNumber(this.HealthCM.vitaminStd);
      this.HealthCM.proteinWeight = this.formattedNumber(this.HealthCM.proteinWeight);
      this.HealthCM.fatWeight = this.formattedNumber(this.HealthCM.fatWeight);
      this.HealthCM.carbonWaterWeight = this.formattedNumber(this.HealthCM.carbonWaterWeight);
      this.HealthCM.vitaminWeight = this.formattedNumber(this.HealthCM.vitaminWeight);
    },
    cal_calories_std() {
      this.calDataLoad = true;
      this.clear_cal_calories_std();
      setTimeout(() => {
        this.HealthCM.calCalorGap = this.HealthCM.calories - this.HealthCM.calorGap;
        // this.HealthCM.calories = this.HealthCM.calCalorGap;
        // 蛋白质系数是4，计算s公式（举例：某人体重在150斤*4=600大卡）
        this.HealthCM.proteinStd = (2 * this.HealthCM.weight) * this.HealthCM.proteinFactor;
        this.HealthCM.proteinWeight = (2 * this.HealthCM.weight) * 1
        if (this.HealthCM.calories != 0) {
          // 脂肪系数是15%，9，计算公式（举例： 体重在150斤，每日需要摄入1500大卡热量，1500大卡*0.15=225大卡÷9=25g）
          this.HealthCM.fatStd = (parseFloat(this.HealthCM.calories) * parseFloat(this.HealthCM.fatCoefficient));
          this.HealthCM.fatWeight = this.HealthCM.fatStd / 9;
          if (this.HealthCM.carbonWaterCoefficient != 0) {
            // 碳水化合物系数是4，公式<举例：某人体重在150斤，每日需要摄入1500大卡热量，1500大卡（总热量）-225大卡（脂肪大卡）-600大卡（蛋白质大卡）=675大卡（每日所摄入的大卡） 675大卡÷4=168g
            this.HealthCM.carbonWaterStd = (parseFloat(this.HealthCM.calories) - parseFloat(this.HealthCM.fatStd) - parseFloat(this.HealthCM.proteinStd));
            this.HealthCM.carbonWaterWeight = this.HealthCM.carbonWaterStd / 4
          }
        }
        // 摄入总热量 * 维他命计算系数%
        this.format_cal_calories_weight();
        this.calDataLoad = false;
      }, 1500);
    },
    cal_DailyTake(val, flg, row) {
      let res = parseFloat(this.HealthCM.calories) * parseFloat(row.combinationRatio / 100) * parseInt(row.standardUnit);
      row.totalDailyIntake = this.formattedNumber(res);
      let add_flg = true;
      let rpl_index = 0;
      for (let _index = 0; _index < this.calParamIdx.length; _index++) {
        let item = this.calParamIdx[_index];
        if (item == row.id) {
          add_flg = false;
          rpl_index = _index;
          break;
        }
      }
      if (add_flg) {
        this.calParamIdx.push(row.id);
        this.calParam.push({
          "id": row.id,
          "classification": row.classification,
          "combinationRatio": row.combinationRatio,
          "count": row.count,
          "totalDailyIntake": row.totalDailyIntake
        });
      } else {
        this.calParam[rpl_index] = {
          "id": row.id,
          "classification": row.classification,
          "combinationRatio": row.combinationRatio,
          "count": row.count,
          "totalDailyIntake": row.totalDailyIntake
        }
      }
      this.claflg = true;
    },
    formattedNumber(number) {
      const num = parseFloat(number); // 先将传入的值转换成浮点数类型
      if (!isNaN(num)) { // 判断是否能正常转换成数字
        return num.toFixed(2).toString(); // 返回保留两位小数后的结果
      } else {
        return ''; // 若传入值无法转换成数字，则返回空字符串
      }
    },
    childMethod() {
      this.tableData = [];
      this.tableData2 = [];
      this.HealthCM = null;
      this.$emit('fMethod');
    },
  },
  created() {
    let options = {fullscreen: true}
    this.loadingInstance = Loading.service(options);
    this.loadingInstance.close();
  },
  mounted() {
  },
  watch: {
    drawId: {
      immediate: true,
      handler(drawId) {
        if (drawId.length > 0) {
          this.member_id = drawId;
          this.handle_init();
        }
      }
    }
  }
}
</script>

<style scoped>
li {
  list-style-type: none;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.fstRow {
  margin-top: 0px;
  display: flex;
  padding: 5px 5px 5px 5px;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

#container > div {
  margin: 5px;
  width: 400px; /*宽度根据实际情况调节，应与上面一致*/
  overflow: auto; /*防止内容溢出导致布局错位*/
}

.dinnerCard {
  padding: 5 5 5 5;
  margin-top: 15px;
}
</style>